<?php
if ( !defined( "IN_OP" ) )
{
    exit( "You can't access this file directly..." );
}
if ( ( $curruser['acl'] < 255 || $curruser['acl'] == 255 && $curruser['prev_id'] != 0 ) && !SubAccountRight( $curruser, 1 ) )
{
    diemsg( "你不是管理者！" );
}
$ui = new UI();
$tpl = new Template2();
$conf = new Config();
$rs = getdb( "select * from lotto where open>='".date( "Y-m-d" )."' order by open" );
if ( $rs->eof )
{
    $ui->showErrorPage( "<p class=error>目前没有可以下注期数！</p>" );
    exit();
}
$open = $rs->f['open'];
$round = $rs->f['round'];
$lotto_id = $rs->f['id'];
$opnumber = $rs->f['n1'];
$rs->close();
$stopbet = $conf->get( "waitbet" );
$startmode = "";
if ( date( "Y-m-d" ) < $open )
{
    $startmode = "disabled";
}
else if ( date( "Y-m-d" ) == $open )
{
    if ( $stopbet <= date( "Hi" ) && 0 < $opnumber )
    {
        $startmode = "disabled";
    }
    else if ( date( "Hi" ) <= $conf->get( "startbet" ) )
    {
        $startmode = "disabled";
    }
}
$dt = date( "Y-m-d" );
$t1 = strtotime( $open." ".$stopbet );
$tpl->Set( "timestap", $t1 - systime( ) );
$tpl->set( "phptime", systime( ) );
$tpl->set( "open", $open );
$tpl->set( "round", d3( $round ) );
$tpl->set( "dt", $dt );
$tpl->set( "lotto_id", $lotto_id );
$total_win = 0;
$ary = array( "rate" => 0, "amount" => 0, "count" => 0, "lost" => 0 );
$sql = "select amount,upercent,back5,rate from bet where lotto_id=".$lotto_id." and bettype=12 and rame in (0,9)";
$rs = getdb( $sql );
while ( !$rs->eof )
{
    $percent = 1;
    $percent = $rs->f['upercent'];
    if ( 0 < $percent )
    {
        $percent /= 100;
    }
    $tmp = $percent * $rs->f['amount'];
    $ary['amount']  += $tmp;
    ++$ary['count'];
    $ary['lost'] ++;
    $total_win += $tmp * ( $rs->f['back5'] / 100 );
    $rs->movenext();
}
$rs->close();
$sql = "select amount,percent255,back5,rate from bet2 where lotto_id=".$lotto_id." and bettype=12 and rame in (0,9)";
$rs = getdb( $sql );
while ( !$rs->eof )
{
    $percent = $rs->f['percent255'];
    if ( 0 < $percent )
    {
        $percent /= 100;
    }
    $tmp = $percent * $rs->f['amount'];
    $ary['amount']  += $tmp;
    ++$ary['count'];
    $ary['lost'] ++;
    $total_win += $tmp * ( $rs->f['back5'] / 100 );
    $rs->movenext();
}
$rs->close();
$sql = "select amount,back,rate from bet8 where lotto_id=".$lotto_id." and bettype=12 and rame in (0,9)";
$rs = getdb( $sql );
while ( !$rs->eof )
{
    $backs = $rs->f['back'];
    $tmp = $rs->f['amount'];
    $ary['amount']  -= $tmp;
    $ary -= "lost";
    $total_win -= $tmp * ( ( 100 - $backs ) / 100 );
    $rs->movenext();
}
$rs->close();
$i = 1;
while ( $i <= 6 )
{
    $j = 1;
    while ( $j <= 7 )
    {
        $tpl->set( "r12_".$i."_".$j, "" );
        ++$j;
    }
    ++$i;
}
$b91 = isset( $_COOKIE['b91'] ) ? $_COOKIE['b91'] : "";
$tpl->set( "b91", $b91 );
$b92 = "";
$tpl->set( "b92", $b92 );
$tpl->set( "startnowdisable", $startmode );
$tpl->set( "money", $ary['amount'] );
$tpl->set( "win", show_numbercolor( $total_win - $ary['lost'] ) );
$prot_user = array();
$j = 0;
$i = 0;
while ( $i < 10 )
{
    $name = $conf->get( "port_systemuser_".$i );
    if ( $name != "" )
    {
        $prot_user[$j] = $name;
        ++$j;
    }
    ++$i;
}
$userrame1 = "&nbsp;<select name=account style='display:none'><option value='' selected> </option>";
$i = 0;
while ( $i < $j )
{
    $userrame1 .= "<option value='".$prot_user[$i]."'>".$prot_user[$i]."</option>";
    ++$i;
}
$userrame1 .= "</select>";
$tpl->set( "select_usr1", $userrame1 );
include_once( "class_6h/class.menu.php" );
$fieldArr = array( "round" => $round, "open" => $open, "lotto_id" => $lotto_id, "split_id" => 1 );
$onlineMenu = new menu_6h( 2, $fieldArr );
$selectid = getvar( "select" ) == "" ? 0 : getvar( "select" );
$menuList = $onlineMenu->getMenu( $selectid );
$tpl->set( "menuList", $menuList );
$tpl->set( "selectid", $selectid );
unset( $onlineMenu );
$tpl->load( "main", "unow9.htm" );
$tpl->set( "jslang", $g_conf['language'] );
$tpl->show( "main" );
$ui->footer();
?>